package com.compomics.fspike.playground;

import com.compomics.fspike.gui.taxonomytree.rendering.TaxonomyTreeIconFactory;
import com.compomics.fspike.gui.taxonomytree.rendering.TaxonomyTreeIconRenderer;
import com.compomics.fspike.gui.taxonomytree.rendering.DefaultTaxonomyTreeNode;
import com.compomics.fspike.gui.taxonomytree.NCBITaxonomyTree;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.MalformedURLException;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalIconFactory;
import javax.swing.tree.DefaultTreeModel;

/**
 * @version 1.0 01/12/99
 */
public class IconNodeTreeExample extends JFrame {

    public IconNodeTreeExample() throws MalformedURLException {
        super("IconNode TreeExample");

        String[] strs = {"ROOT", // 0
            "cellular organisms", // 1
            "Eukaryota", // 2
            "Bacteria", // 3
            "Archaea", // 4
    }; // 9

        NCBITaxonomyTree tree = new NCBITaxonomyTree();

        tree.setCellRenderer(new TaxonomyTreeIconRenderer(tree));
        // set Icon directly
        tree.putClientProperty("JTree.icons", TaxonomyTreeIconFactory.getInstance().makeIcons(tree));

        DefaultTaxonomyTreeNode[] nodes = new DefaultTaxonomyTreeNode[strs.length];
        for (int i = 0; i < strs.length; i++) {
            nodes[i] = new DefaultTaxonomyTreeNode(strs[i]);
        }
        nodes[0].setIcon(MetalIconFactory.getTreeLeafIcon());
        nodes[2].setIconName("EUK");
        nodes[3].setIconName("BAC");
        nodes[4].setIconName("ARC");
        nodes[0].add(nodes[1]);
        nodes[1].add(nodes[2]);
        nodes[1].add(nodes[3]);
        nodes[1].add(nodes[4]);
        ((DefaultTreeModel) tree.getModel()).setRoot(nodes[0]);
        tree.updateUI();
        JScrollPane sp = new JScrollPane(tree);
        getContentPane().add(sp, BorderLayout.CENTER);

    }

    public static void main(String args[]) throws MalformedURLException {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception evt) {
        }

        IconNodeTreeExample frame = new IconNodeTreeExample();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setSize(300, 150);
        frame.setVisible(true);
    }
}
